old or incomplete functions and files/p2phylo.R

p2phylo <- function(p){
  t=p$t
  n=p$n
  E=p$E
  newick = paste(sl[1],";",sep="")
  for (i in 1:length(t)){
    nt = read.tree(text=newick)
    # speciation
    if (E[i] == 1){
      spec = sample(1:n[i],1)
      species = nt$tip.label[spec]
      ind = regexpr(species,newick)[1]-1
      atm = ...
      newick = paste(substr(newick,1,ind),"(",substr(newick,ind+1,ind+4),",",sl[i+1],"):",as.character(atm),substring(newick,ind+5),sep="")
    }
    # extinction
    if (E[i]==0){
      species = identf[BD-N,1]
      ind = regexpr(species,newick)[1] + 2
      atm = sumt-identf[which(identf[,1]==species),2]
      identf = identf[-(BD-N),]
      L[L$spec == species,]$ext_time = sumt
      newick = paste(substr(newick,1,ind),as.character(atm),substring(newick,ind+2),sep="")
    }
  }

}
franciscorichter/dmea documentation built on May 16, 2019, 1:54 p.m.